package com.lkd.controller;

import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.lkd.entity.Classify;
import com.lkd.service.ClassifyService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yan
 * @version 1.0
 * Create by 2024-8-19 14:15
 * 分类管理
 */
@RestController
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;

    //添加分类
    @PostMapping("/api/vm-service/skuClass")
    public Result addClassify (@RequestBody Classify classify) {
        boolean save = classifyService.addClassify (classify);
        return Result.success (save);
    }

    //分类搜索
    @GetMapping("/api/vm-service/skuClass/search")
    public Result searchByPage (String className,
          @RequestParam(defaultValue = "1") Integer pageIndex,
          @RequestParam(defaultValue = "2") Integer pageSize
    ) {
        PageBean<Classify> pageBean = classifyService. searchByPage(pageIndex,pageSize,className);
        return Result.success (pageBean);
    }

//    获取分类基本信息
    @GetMapping("/api/vm-service/skuClass/{classId}")
    public Result getBaseMsg(@PathVariable String classId){
        Classify classify = classifyService.getBaseMsg (classId);
        return Result.success (classify);
    }

    //修改分类
    @PutMapping("/api/vm-service/skuClass")
    public  Result update(@RequestBody Classify classify){

        boolean  update = classifyService.updateById (classify);
        return Result.success (update);
    }

    //删除分类
    //todo 逻辑删除
    @DeleteMapping("/api/vm-service/skuClass/{classId}")
    public Result delete(@PathVariable String classId){
        boolean delete = classifyService.removeById (classId);
        return Result.success (delete);
    }
}
